package com.zhilianbao.leyaogo.ui.adapter.me;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ScrollView;
import android.widget.TextView;

import com.zhilianbao.leyaogo.R;
import com.zhilianbao.leyaogo.model.response.me.MyOrderResponse;
import com.zhilianbao.leyaogo.utils.ImageUtils;
import com.zhilianbao.leyaogo.utils.Utils;
import com.zhilianbao.leyaogo.view.widgets.MoneyTextView;

import java.util.List;

/**
 * Created by liu on 2016/10/25.
 * 订单详情ListView的adapter
 */
public class OrderDetailListAdapter extends BaseAdapter {
    Context mContext;
    List<MyOrderResponse.OrderItemBean> mOrderItem;

    public OrderDetailListAdapter(Context context, List<MyOrderResponse.OrderItemBean> orderItem) {
        this.mContext = context;
        this.mOrderItem = orderItem;
    }

    @Override
    public int getCount() {
        return mOrderItem == null ? 0 : mOrderItem.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = View.inflate(mContext, R.layout.item_order_detail, null);
            holder.goodsIcon = (ImageView) convertView.findViewById(R.id.goods_icon);
            holder.goodsTitle = (TextView) convertView.findViewById(R.id.goods_detail_title);
            holder.goodsDesc = (TextView) convertView.findViewById(R.id.goods_detail_content);
            holder.goodsPrice = (MoneyTextView) convertView.findViewById(R.id.goods_detail_price);
            holder.goodsNum = (TextView) convertView.findViewById(R.id.goods_detail_num);
            holder.grayDevider = convertView.findViewById(R.id.view_gray_devide);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        MyOrderResponse.OrderItemBean orderItemBean = mOrderItem.get(position);
        ImageUtils.loadGoodsPic(Utils.returnUrlShow(orderItemBean.getGoodsPic()), holder.goodsIcon);
        holder.goodsTitle.setText(orderItemBean.getGoodsName());
        if (orderItemBean.getGoodsSkuId() != 0) {//是sku商品
            holder.goodsDesc.setText(orderItemBean.getGoodsSkuName());
        } else {//不是sku商品
            holder.goodsDesc.setText(orderItemBean.getGoodsDesc());
        }
        holder.goodsPrice.setAmount(orderItemBean.getUnitPrice());
        holder.goodsNum.setText("x " + orderItemBean.getNumber());
        if (position == getCount() - 1) {
            holder.grayDevider.setVisibility(View.GONE);
        } else {
            holder.grayDevider.setVisibility(View.VISIBLE);
        }
        return convertView;
    }

    class ViewHolder {
        ImageView goodsIcon;
        TextView goodsTitle;
        TextView goodsDesc;
        MoneyTextView goodsPrice;
        TextView goodsNum;
        View grayDevider;
    }
}
